/**
 * 实体
 */
Ext.define('cc.noself.view.NoSelfBus', {
	extend: 'Ext.form.Panel',
	uses: ['cc.util.NoselfService'],
	layout: 'form',
	
	//是否显示编辑器
	enableEdt: true,
	
	defaults: {
		xtype: 'textfield',
		labelWidth: 60,
		margin: '10 10 0 10'
	},

	viewModel: {
		data: {
			rec: null
		}
	},

	initComponent: function() {
		var me = this;

		me.items = [{
			xtype: me.enableEdt ? 'textfield' : 'displayfield',
			fieldLabel: '',
			bind: '{rec.id}'
		}, {
			xtype: me.enableEdt ? 'textfield' : 'displayfield',
			fieldLabel: '',
			bind: '{rec.code}'
		}, {
			xtype: me.enableEdt ? 'textfield' : 'displayfield',
			fieldLabel: '',
			bind: '{rec.wx_no}'
		}, {
			xtype: me.enableEdt ? 'textfield' : 'displayfield',
			fieldLabel: '',
			bind: '{rec.gs_no}'
		}, {
			xtype: me.enableEdt ? 'textfield' : 'displayfield',
			fieldLabel: '',
			bind: '{rec.customer}'
		}, {
			xtype: me.enableEdt ? 'textfield' : 'displayfield',
			fieldLabel: '',
			bind: '{rec.bg_date}'
		}, {
			xtype: me.enableEdt ? 'textfield' : 'displayfield',
			fieldLabel: '',
			bind: '{rec.bg_no}'
		}, {
			xtype: me.enableEdt ? 'textfield' : 'displayfield',
			fieldLabel: '',
			bind: '{rec.bg_money}'
		}, {
			xtype: me.enableEdt ? 'textfield' : 'displayfield',
			fieldLabel: '',
			bind: '{rec.port_from}'
		}, {
			xtype: me.enableEdt ? 'textfield' : 'displayfield',
			fieldLabel: '',
			bind: '{rec.port_to}'
		}, {
			xtype: me.enableEdt ? 'textfield' : 'displayfield',
			fieldLabel: '',
			bind: '{rec.ts_date}'
		}, {
			xtype: me.enableEdt ? 'textfield' : 'displayfield',
			fieldLabel: '',
			bind: '{rec.bus_way}'
		}, {
			xtype: me.enableEdt ? 'textfield' : 'displayfield',
			fieldLabel: '',
			bind: '{rec.get_way}'
		}, {
			xtype: me.enableEdt ? 'textfield' : 'displayfield',
			fieldLabel: '',
			bind: '{rec.ny_org}'
		}, {
			xtype: me.enableEdt ? 'textfield' : 'displayfield',
			fieldLabel: '',
			bind: '{rec.ny_date}'
		}, {
			xtype: me.enableEdt ? 'textfield' : 'displayfield',
			fieldLabel: '',
			bind: '{rec.ny_money}'
		}, {
			xtype: me.enableEdt ? 'textfield' : 'displayfield',
			fieldLabel: '',
			bind: '{rec.zf_org}'
		}, {
			xtype: me.enableEdt ? 'textfield' : 'displayfield',
			fieldLabel: '',
			bind: '{rec.zf_date}'
		}, {
			xtype: me.enableEdt ? 'textfield' : 'displayfield',
			fieldLabel: '',
			bind: '{rec.zf_money}'
		}, {
			xtype: me.enableEdt ? 'textfield' : 'displayfield',
			fieldLabel: '',
			bind: '{rec.dz_org}'
		}, {
			xtype: me.enableEdt ? 'textfield' : 'displayfield',
			fieldLabel: '',
			bind: '{rec.dz_date}'
		}, {
			xtype: me.enableEdt ? 'textfield' : 'displayfield',
			fieldLabel: '',
			bind: '{rec.dz_money}'
		}, {
			xtype: me.enableEdt ? 'textfield' : 'displayfield',
			fieldLabel: '',
			bind: '{rec.kj_org}'
		}, {
			xtype: me.enableEdt ? 'textfield' : 'displayfield',
			fieldLabel: '',
			bind: '{rec.kj_date}'
		}, {
			xtype: me.enableEdt ? 'textfield' : 'displayfield',
			fieldLabel: '',
			bind: '{rec.kj_money}'
		}, {
			xtype: me.enableEdt ? 'textfield' : 'displayfield',
			fieldLabel: '',
			bind: '{rec.dl_org}'
		}, {
			xtype: me.enableEdt ? 'textfield' : 'displayfield',
			fieldLabel: '',
			bind: '{rec.dl_date}'
		}, {
			xtype: me.enableEdt ? 'textfield' : 'displayfield',
			fieldLabel: '',
			bind: '{rec.dl_money}'
		}, {
			xtype: me.enableEdt ? 'textfield' : 'displayfield',
			fieldLabel: '',
			bind: '{rec.jh_money}'
		}, {
			xtype: me.enableEdt ? 'textfield' : 'displayfield',
			fieldLabel: '',
			bind: '{rec.cg_money}'
		}, {
			xtype: me.enableEdt ? 'textfield' : 'displayfield',
			fieldLabel: '',
			bind: '{rec.ts_money}'
		}, {
			xtype: me.enableEdt ? 'textfield' : 'displayfield',
			fieldLabel: '',
			bind: '{rec.other_money}'
		}, {
			xtype: me.enableEdt ? 'textfield' : 'displayfield',
			fieldLabel: '',
			bind: '{rec.payed_money}'
		}, {
			xtype: me.enableEdt ? 'textfield' : 'displayfield',
			fieldLabel: '',
			bind: '{rec.paying_money}'
		}, {
			xtype: me.enableEdt ? 'textfield' : 'displayfield',
			fieldLabel: '',
			bind: '{rec.jssxf}'
		}, {
			xtype: me.enableEdt ? 'textfield' : 'displayfield',
			fieldLabel: '',
			bind: '{rec.kjscj}'
		}, {
			xtype: me.enableEdt ? 'textfield' : 'displayfield',
			fieldLabel: '',
			bind: '{rec.remark}'
		}, {
			xtype: me.enableEdt ? 'textfield' : 'displayfield',
			fieldLabel: '',
			bind: '{rec.ywy}'
		}, {
			xtype: me.enableEdt ? 'textfield' : 'displayfield',
			fieldLabel: '',
			bind: '{rec.ywy_date}'
		}, {
			xtype: me.enableEdt ? 'textfield' : 'displayfield',
			fieldLabel: '',
			bind: '{rec.zdr}'
		}, {
			xtype: me.enableEdt ? 'textfield' : 'displayfield',
			fieldLabel: '',
			bind: '{rec.zd_date}'
		}, {
			xtype: me.enableEdt ? 'textfield' : 'displayfield',
			fieldLabel: '',
			bind: '{rec.shr}'
		}, {
			xtype: me.enableEdt ? 'textfield' : 'displayfield',
			fieldLabel: '',
			bind: '{rec.sh_date}'
		}, {
			xtype: me.enableEdt ? 'textfield' : 'displayfield',
			fieldLabel: '',
			bind: '{rec.cdr}'
		}, {
			xtype: me.enableEdt ? 'textfield' : 'displayfield',
			fieldLabel: '',
			bind: '{rec.cd_date}'
		}, {
			xtype: me.enableEdt ? 'textfield' : 'displayfield',
			fieldLabel: '',
			bind: '{rec.valid}'
		}];

		me.callParent(arguments);
	},

	save: function(cb) {
		var me = this;
		var rec = me.getViewModel().getData().rec;
		var d = rec.getData();
		if(rec.get('id') > 0){
			//update
			CC.Noself.updateNoSelfBus({data: Ext.encode(d)}, function(){
				rec.commit();
				if(cb){
					cb(rec);
				}
			});
		}else{
			//create
			CC.Noself.createNoSelfBus({data: Ext.encode(d)}, function(data){
				rec.set('id', data.id);
				rec.commit();
				if(cb){
					cb(rec, true);
				}
			});
		}
	},
	
	loadEntity: function(key){
		var me = this;
		CC.Noself.getNoSelfBus(key, function(data){
			me.getViewModel().set('rec', Ext.create('cc.noself.model.NoSelfBus', data));
		});
	}
});
